<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var num1 = [1, 2, 3, 2,1, 2, 4];
      var num2 = [1, 3, 7];
   //思路：先过滤一个数组，然后拿这个数组的里面的值  跟另外一个数组的值对比


//俩个数组的交集
      var res = num1.filter(function (item, index) {
        return num2.indexOf(item) !== -1;
      });

      //给res  去掉重复的数据

    var res1=  res.reduce(function(pre,cur){

       if(pre.indexOf(cur)===-1){
        return pre.concat(cur)
       }else {
         return pre
       }
      },[])

     console.log(res1)

    </script>
  </body>
</html>
